package com.accenture.adf.newcodington.module8.sample;

/*
 * Travel Pass Lottery Demo is about choosing lucky winner among the ticket ID's generated
 * 
 * Topic: Demo on linear search using single dimensional array
 * 
 * Instructions:
 * 1. Create a class named TravelPassLottery_Demo1 with main method() and apply following changes
 * 2. Declare an integer variable for tracking no of tickets to be issued
 * 3. Declare an integer single dimensional array for storing ticket id's for each of the tickets
 * 4. Declare an integer variable for generated ticket id
 * 5. Declare a boolean variable for winner found flag
 * 6. Initialize the variables no of tickets, the array with no of tickets as the size
 * 7. Print a message to the console as 'Travel Pass Lottery - Choosing Winner'
 * 8. Use for loop with noOfTickets as the boundary to populate the ticket id array
 * 		a. Ticket ID can be generated by adding 1 to the loop index
 * 		b. Assign ticket id generated to the respective index in the ticket id array
 * 9. Assign some random integer as the lucky winner id, store this value in ticket id
 * 10. Use for loop to check the ticket id values with array length as the boundary
 * 		a. Check each array value if it matches with the lucky winner id
 * 		b. If matches, set winner found to true and break the loop
 * 		c. If winner found is true, print a message to the console as 'Hurrah, winner among us'
 * 		d. If winner found false, print a message to the console as 'Oops, winner not among us'
 * 
 */


public class TravelPassLottery_Demo1 {
	
	public static void main(String[] args){	
		
		int noOfTickets;		
		int[] ticketID;
		int passID;		
		boolean foundWinner = false;		
				
		noOfTickets = 5;
		ticketID = new int[noOfTickets];		
		
		System.out.println("Travel Pass Lottery - Choosing Winner");
		
		//Populate single dimensional array
		for(int i=0;i<noOfTickets;i++){
			passID = i + 1;
			ticketID[i] = passID;			
		}		
				
		//Pick the winner pass
		passID = 3;	//assign some random number, try with a number less than noOfTickets and with a number greater than noOfTickets	
		
		//Match the winner among our team
		for(int i=0;i<ticketID.length;i++){
			if(ticketID[i] == passID){				
				foundWinner = true;
				break;
			}	
		}
		
		if(foundWinner)
			System.out.println("Hurrah!! Winner among us, winner ticket id: "+passID);
		else
			System.out.println("OOps!! Winner not among us");		
	}	
	
}
